package com.seekting.mynews.manager;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.LruCache;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.ImageLoader.ImageCache;
import com.seekting.mynews.volley.NewsVolley;

public class VolleyRequestManager extends Manager {

    Context mContext;
    private RequestQueue mRequestQueue;
    private ImageLoader imageLoader;
    private BitmapRatioManager mBitmapRatioManager;

    public BitmapRatioManager getBitmapRatioManager() {
        return mBitmapRatioManager;
    }

    public VolleyRequestManager(Context context) {
        super(context);
        mBitmapRatioManager = new BitmapRatioManager(context);
        mContext = context;
        mRequestQueue = NewsVolley.newRequestQueue(context);
        ImageCache imageCache = new ImageCache() {
            LruCache<String, Bitmap> lruCache = new LruCache<String, Bitmap>(30) {
                @Override
                protected int sizeOf(String key, Bitmap value) {
                    return 1;
                }
            };

            @Override
            public void putBitmap(String url, Bitmap bitmap) {
                lruCache.put(url, bitmap);

            }

            @Override
            public Bitmap getBitmap(String url) {
                return lruCache.get(url);
            }
        };
        imageLoader = new ImageLoader(mRequestQueue, imageCache);
    }

    public RequestQueue getRequestQueue() {
        return mRequestQueue;
    }

    public ImageLoader getImageLoader() {
        return imageLoader;
    }
}
